package com.xiaomi.servlet;


import com.xiaomi.entity.Page;
import com.xiaomi.entity.Product;
import com.xiaomi.service.ProductService;
import com.xiaomi.service.impl.ProductServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * TODO
 *
 * @author jy
 * @date 2021/5/24
 */
@WebServlet("/product")
public class ProductServlet extends BaseServlet {

    private final ProductService productService = new ProductServiceImpl();

    /**
     * 查询当前页所有的数据,返回给goodsList.jsp
     */
    protected String list(HttpServletRequest req, HttpServletResponse resp) {
        String tid = req.getParameter("tid");
        String curPage = req.getParameter("curPage");
        Page<Product> page = productService.list(tid, curPage);
        req.setAttribute("page", page);
        return "forward:/goodsList.jsp";
    }

    /**
     * 通过产品id查询出详细信息,返回给goodsDetail.jsp
     */
    protected String getProductByPid(HttpServletRequest req, HttpServletResponse resp) {
        String pid = req.getParameter("pid");
        Product product = productService.getProductByPid(pid);
        req.setAttribute("goods", product);
        return "forward:/goodsDetail.jsp";
    }
}
